home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / xml / SchemaValidator.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  3.1 KB  |  154 lines

  1. package com.extensibility.xml;
  2.  
  3. import java.awt.Toolkit;
  4. import java.util.Enumeration;
  5. import java.util.Vector;
  6.  
  7. public class SchemaValidator implements Runnable {
  8.    boolean exitNow = false;
  9.    Vector dirtyDecls = new Vector();
  10.    SchemaIntf schema;
  11.    boolean schemaDirty;
  12.  
  13.    public SchemaValidator(SchemaIntf var1) {
  14.       this.schema = var1;
  15.    }
  16.  
  17.    public void run() {
  18.       try {
  19.          Object var1 = null;
  20.  
  21.          while(true) {
  22.             BaseDeclaration var4 = this.getNextDecl();
  23.             if (this.exitNow) {
  24.                this.dirtyDecls = null;
  25.                return;
  26.             }
  27.  
  28.             if (var4 == null) {
  29.                this.schema.checkForErrors((BaseDeclaration)null);
  30.             } else {
  31.                boolean var2 = var4.hasErrors();
  32.                this.schema.checkForErrors(var4);
  33.                if (var2 != var4.hasErrors()) {
  34.                   var4.fireChangeEvent(99, (Object)null);
  35.                }
  36.             }
  37.          }
  38.       } catch (RuntimeException var3) {
  39.          Toolkit.getDefaultToolkit().beep();
  40.          ((Throwable)var3).printStackTrace();
  41.          throw var3;
  42.       }
  43.    }
  44.  
  45.    private synchronized BaseDeclaration getNextDecl() {
  46.       try {
  47.          while(!this.exitNow) {
  48.             if (!this.dirtyDecls.isEmpty()) {
  49.                BaseDeclaration var4 = (BaseDeclaration)this.dirtyDecls.lastElement();
  50.                this.dirtyDecls.removeElementAt(this.dirtyDecls.size() - 1);
  51.                return var4;
  52.             }
  53.  
  54.             if (this.schemaDirty) {
  55.                this.schemaDirty = false;
  56.                Object var1 = null;
  57.                return (BaseDeclaration)var1;
  58.             }
  59.  
  60.             this.wait();
  61.          }
  62.  
  63.          Object var5 = null;
  64.          return (BaseDeclaration)var5;
  65.       } catch (InterruptedException var3) {
  66.          return null;
  67.       }
  68.    }
  69.  
  70.    public synchronized void exit() {
  71.       this.exitNow = true;
  72.       this.notifyAll();
  73.    }
  74.  
  75.    public synchronized void addAll() {
  76.       this.removeAll();
  77.       this.add(this.schema.getDeclarations());
  78.    }
  79.  
  80.    public synchronized void addAll(URI var1) {
  81.       this.add(this.schema.getDeclarations(var1, false));
  82.    }
  83.  
  84.    public synchronized void checkAll() {
  85.       this.removeAll();
  86.       boolean var1 = false;
  87.       Enumeration var2 = this.schema.getDeclarations();
  88.  
  89.       while(var2.hasMoreElements()) {
  90.          BaseDeclaration var3 = (BaseDeclaration)var2.nextElement();
  91.          boolean var4 = var3.hasErrors();
  92.          var1 |= var4;
  93.          this.schema.checkForErrors(var3);
  94.          if (var4 != var3.hasErrors()) {
  95.             var3.fireChangeEvent(99, (Object)null);
  96.          }
  97.       }
  98.  
  99.       this.schema.checkForErrors((BaseDeclaration)null);
  100.       if (this.schema.getParseErrors().size() > 0) {
  101.          var1 = true;
  102.       }
  103.  
  104.       if (!var1 && this.schema.isSupported("GESTALT_SECOND_PASS_VALIDATION")) {
  105.          this.schema.doSecondPassValidation((URI)null);
  106.       }
  107.  
  108.       this.schemaDirty = false;
  109.    }
  110.  
  111.    private synchronized void add(Enumeration var1) {
  112.       while(var1.hasMoreElements()) {
  113.          BaseDeclaration var2 = (BaseDeclaration)var1.nextElement();
  114.          this.dirtyDecls.addElement(var2);
  115.       }
  116.  
  117.       this.schemaDirty = true;
  118.       this.notifyAll();
  119.    }
  120.  
  121.    public synchronized void add(BaseDeclaration var1) {
  122.       if (this.check(var1)) {
  123.          this.schemaDirty = true;
  124.          this.notifyAll();
  125.       }
  126.  
  127.    }
  128.  
  129.    private synchronized boolean check(BaseDeclaration var1) {
  130.       if (!this.dirtyDecls.contains(var1)) {
  131.          this.dirtyDecls.addElement(var1);
  132.          this.notifyAll();
  133.          return true;
  134.       } else {
  135.          return false;
  136.       }
  137.    }
  138.  
  139.    public synchronized void remove(BaseDeclaration var1) {
  140.       this.dirtyDecls.removeElement(var1);
  141.    }
  142.  
  143.    public synchronized void removeAll() {
  144.       for(int var1 = this.dirtyDecls.size() - 1; var1 >= 0; --var1) {
  145.          this.remove((BaseDeclaration)this.dirtyDecls.elementAt(var1));
  146.       }
  147.  
  148.    }
  149.  
  150.    public synchronized boolean isDone() {
  151.       return this.dirtyDecls.isEmpty() && !this.schemaDirty;
  152.    }
  153. }
  154.